package com.agricultural;

import com.agricultural.command.CommandInvoker;
import com.agricultural.command.impl.ExecuteWorkCommand;
import com.agricultural.command.impl.StartCommand;
import com.agricultural.command.impl.StopCommand;
import com.agricultural.management.CloudPlatform;
import com.agricultural.equipment.AgriculturalEquipment;
import com.agricultural.strategy.impl.DefaultPathStrategy;
import com.agricultural.strategy.impl.WetSoilPathStrategy;

// 应用主类
public class App {
    public static void main(String[] args) {
        // 创建云端管理平台
        CloudPlatform platform = new CloudPlatform();
        
        // 添加设备
        platform.addEquipment("tractor", "T001");//拖拉机
        platform.addEquipment("seeder", "S001");//播种机
        platform.addEquipment("sprayer", "P001");//喷药机
        platform.addEquipment("harvester", "H001");//收割机
        
        // 获取设备
        AgriculturalEquipment tractor = platform.getEquipment("T001");
        AgriculturalEquipment seeder = platform.getEquipment("S001");
        
        // 设置路径规划策略
        tractor.setPathPlanningStrategy(new DefaultPathStrategy());
        seeder.setPathPlanningStrategy(new DefaultPathStrategy());
        
        // 显示所有设备状态
        platform.showAllEquipmentStatus();
        
        // 创建命令调用者
        CommandInvoker invoker = new CommandInvoker();
        
        // 执行命令
        System.out.println("\n===== 执行命令 =====");
        invoker.executeCommand(new StartCommand(tractor));
        invoker.executeCommand(new StartCommand(seeder));
        invoker.executeCommand(new ExecuteWorkCommand(tractor));
        invoker.executeCommand(new ExecuteWorkCommand(seeder));
        
        // 模拟环境变化
        System.out.println("\n===== 模拟环境变化 =====");
        platform.updateEnvironmentData("soilMoisture", 85.0); // 高湿度
        
        // 为播种机切换策略
        seeder.setPathPlanningStrategy(new WetSoilPathStrategy());
        
        // 重新规划路径
        System.out.println("\n===== 重新规划路径 =====");
        tractor.planPath(null);
        seeder.planPath(null);
        
        // 模拟安全事件
        System.out.println("\n===== 模拟安全事件 =====");
        platform.handleSafetyEvent("T001", "obstacle", 1.5); // 检测到近距离障碍物
        
        // 撤销命令
        System.out.println("\n===== 撤销命令 =====");
        invoker.undoLastCommand();
        invoker.undoLastCommand();
        
        // 停止设备
        System.out.println("\n===== 停止设备 =====");
        invoker.executeCommand(new StopCommand(tractor));
        invoker.executeCommand(new StopCommand(seeder));
        
        // 显示最终状态
        System.out.println("\n===== 最终设备状态 =====");
        platform.showAllEquipmentStatus();
    }
}    